package com.dmzc.stage3.AtomicXXX;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;

public class Test {
    public static void main(String[] args) {
//        int i = 7;
//        new Thread() {
//            @Override
//            public void run() {
//                System.out.println(i);
//            }
//        }.start();
        AtomicInteger atomicInteger = new AtomicInteger(0);
        for (int i = 0; i < 30; i++) {
            new Thread("thread" + i) {
                @Override
                public void run() {

                    try {
                        TimeUnit.SECONDS.sleep(1);
                        atomicInteger.getAndIncrement();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
        for (int i = 0; i < 12; i++) {
            new Thread("syso"+i){
                @Override
                public void run() {

                    try {
                        TimeUnit.MILLISECONDS.sleep(12);
                        System.out.println(atomicInteger.get());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }

    }
}